<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class SupervisionOther extends AdminController {

	function __construct() { 
		parent::__construct();
		$this -> load -> model("Folder_model");
		$this -> load -> library("ProjectService/table_service");
		$this -> load -> library("ProjectService/admin_service");
		$this->load->model('Table1_model');
		$this->load->model('Table2_model');
		$this->load->model('Table3_model');
		$this->load->model('Table4_model');
		$this->load->model('Table5_model');
		$this->load->model('Table5_student_model');
		$this->load->model('Table6_model');
        $this->load->model('Other_statistics_model');
        $this->load->model("Admin_model");
	}

	public function Index() {
			//按教师分类
		$connar['items']='distinct(dept_name)';
		$dept_name=$this->Admin_model->get_list_full($connar);
		 $new_dept_name=array();
        foreach($dept_name as $k=>$v){
            if($v['dept_name']){
                $name = mb_substr($v['dept_name'],0,2,"utf-8");             
                if($name =='财经' ||$name =='商贸'||$name =='交通'||$name =='鉴湖'||$name =='黄酒'){
                    $new_dept_name[$k]['name'] = mb_substr($v['dept_name'],0,2,"utf-8");             
                }else if($name =='建筑' ||$name =='机电'||$name =='交通'){
                    $new_dept_name[$k]['name'] = mb_substr($v['dept_name'],0,4,"utf-8");   
                }else if($name =='设计'){
                    $new_dept_name[$k]['name'] = mb_substr($v['dept_name'],0,5,"utf-8");   
                }else{
                    $new_dept_name[$k]['name'] = $v['dept_name'];
                }
                 $new_dept_name[$k]['dept_name'] = $v['dept_name'];
            }           
        }

        $data['dept_name']= $new_dept_name;
		// $data['dept_name']= $dept_name;
		$this -> load -> view('admin/supervisionOther',$data);
	}


	function getFolder($type){
		$sub_role=explode(',', getSess()['sub_role_id']);
		array_push($sub_role, getSess()['role_id']);
		// foreach ($sub_role as $k => $v) {
			if(in_array(WebRole::Manage[XPHEnum::Value], $sub_role)){
				$folder=$this->table_service->getFolderByType($type,getSess()['id'],false,WebRole::Manage[XPHEnum::Value]);
			}else if(in_array(WebRole::SupervisorDirector[XPHEnum::Value], $sub_role) ){
				$folder=$this->table_service->getFolderByType($type,getSess()['id'],false,WebRole::SupervisorDirector[XPHEnum::Value]);
			}else if(in_array(WebRole::SchoolSupervisor[XPHEnum::Value], $sub_role)){
				$folder=$this->table_service->getFolderByType($type,getSess()['id'],false,WebRole::SchoolSupervisor[XPHEnum::Value]);
			}else if(in_array(WebRole::UnitSupervisorGroupLeader[XPHEnum::Value], $sub_role)){
				$folder=$this->table_service->getFolderByType($type,getSess()['id'],false,WebRole::UnitSupervisorGroupLeader[XPHEnum::Value]);
			}else if(in_array(WebRole::Admin[XPHEnum::Value], $sub_role)){
				$folder=$this->table_service->getFolderByType($type,getSess()['id'],false,WebRole::Admin[XPHEnum::Value]);
			}else if(in_array(WebRole::UnitSupervisor[XPHEnum::Value], $sub_role)){
				$folder=$this->table_service->getFolderByType($type,getSess()['id'],false,WebRole::UnitSupervisor[XPHEnum::Value]);
			}

		// }
		// if($is_admin){
		// 	$folder=$this->table_service->getFolderByType($type,getSess()['id'],false,true);
		// }else{
		// 	$folder=$this->table_service->getFolderByType($type,getSess()['id']);
		// }		
		exit(retJson('文件夹',true,$folder));
	}

	function addFolder($type){
		if($_POST['name']==''){
			exit(retJson('请填写文件夹名称',false));
		}
		$folder=$this->table_service->addFolder($type,getSess()['id'],$_POST['name']);
		exit(retJson('文件夹',true,$folder));
	}

	function delFolder($id){
		$this->table_service->delFolder($id);
		exit(retJson('文件夹',true));
	}

	function resetName($id){
		if($_POST['name']==''){
			exit(retJson('请填写文件夹名称',false));
		}
		$folder=$this->table_service->resetName($id,$_POST['name']);
		exit(retJson('文件夹',true,$folder));
	}

	// function getDocument($folder_id){
	// 	$document=$this->table_service->getDocumentByFolderId($folder_id);
	// 	exit(retJson('文件',true,$document));
	// }
	// 根据type获取所有文件信息
	function getDocument($type){
		$parms = $_POST;
		$document=$this->table_service->getDocumentList($type,$parms);
		if($document){
			if($type == 5){
				$document=arraySequence($document,'created','SORT_DESC');//根据二维数组排序
			}else{
				$document=arraySequence($document,'sub_time','SORT_DESC');//根据二维数组排序
			}
			
		}
	
		exit(retJson('文件',true,$document));
	}

	function resetDocumentName($id){
		if($_POST['name']==''){
			exit(retJson('请填写文件名称',false));
		}
		$document=$this->table_service->resetDocumentName($id,$_POST['name'],$_POST['type']);
		exit(retJson('文件',true,$document));
	}

	function delDocument($id){
		$this->table_service->delDocument($id,$_POST['type']);
		// $folder_img=$this->table_service->getFolderImg($id,$_POST['type']);
		// exit(retJson('文件',true,$folder_img));
		exit(retJson('文件',true));
	}

	function tableEdit1($id,$folder_id=false){
		$connar['where']=$this->sqlEscape('db_table1.id=??',array($id));
		$connar['join']=array('db_admin','db_admin.id=db_table1.admin_id');
		$connar['items']="db_table1.*,db_admin.usercode,db_admin.username";
		$data['detail']=$this->Table1_model->get_single_full($connar);

		


		if($id==0){
			$data['title']=OtherTableType::Table1[XPHEnum::Caption]."（新增）";
			$data['SupervisionOtherImg'] = [];

		}
		else{
			$data['title']=OtherTableType::Table1[XPHEnum::Caption]."（".$data['detail']['name']."）";

			// var_dump(explode(',',$data['detail']['img']));

			if(empty($data['detail']['img'])){
				$data['SupervisionOtherImg'] = [];
			}else{
				$data['SupervisionOtherImg'] = explode(',',$data['detail']['img']);
			}
			// var_dump($data['SupervisionOtherImg']);
		}

		$data['folder_id']=$folder_id;

		$data['AttendType']= $this->table_service->getAttendType(getSess()['id'],false);

		

		// var_dump($data);



		$this->load->view('admin/tableEdit1.php',$data);
	}
	function tableSave1(){
		header("Content-Type:text/html; charset=utf-8"); 		
		$_POST['content']=$this->NOTXSS_POST['content'];
		$_POST['advice']=$this->NOTXSS_POST['advice'];
		unset($_POST['editorValue']);

		$table1 = copyArray($_POST,array('id','name',"title","content","advice","sub_time",'folder_id','AttendType'));
		$table1['sub_time']=strtotime($table1['sub_time']);
		if($table1['AttendType'] == '-1'){
			exit(retJson('请选择督导身份',false));
		}
		// //自增字段
		$table1['admin_id']=getSess()['id'];
		$table1['status']=CommonStatus::UnDeleted[XPHEnum::Value];

		if(isset($_POST['SupervisionOtherImg'])){
			$file_img = $_POST['SupervisionOtherImg'];
		}else{
			$file_img = "";
		}

		$table1['img'] = "";
		if(is_array($file_img)){
			foreach($file_img as $k => $v){
				if($k == 0){
					$table1['img'] = $v;
				}else{
					$table1['img'] .= ','.$v;
				}
			}
		}else{
			$table1['img'] = $file_img;
		}

		if(!isset($_POST['id']) || $_POST['id'] == ""){
			$table1['created']=time();
			$id=$this -> Table1_model -> add($table1);
			$document=$this->table_service->getDocumentByIdAndType($id,OtherTableType::Table1[XPHEnum::Value]);

			// 其他材料统计
			$this->otherStatistics($table1['admin_id'], 'specialResearch');

			// $folder_img=$this->table_service->getFolderImg($id,OtherTableType::Table1[XPHEnum::Value]);
			// $folder_document=$this->table_service->getDocumentByFolderId($document['folder_id']);
			// if(count($folder_document)>0){
			// 	$this->Folder_model->update(array('id'=>$document['folder_id'],'is_have'=>CommonWhether::Whether[XPHEnum::Value]));
			// }
			// $remark=array(
			// 	'is_add'=>true,
			// 	'folder_img'=>$folder_img
			// 	);
			// exit(retJson("添加成功.", true,$document,$remark));
			exit(retJson("添加成功.", true,$document));
		}else{	
			unset($table1['name']);
			$table1['updated']=time();
			$this -> Table1_model -> update($table1);
			$document=$this->table_service->getDocumentByIdAndType($table1['id'],OtherTableType::Table1[XPHEnum::Value]);
			// $folder_img=$this->table_service->getFolderImg($table1['id'],OtherTableType::Table1[XPHEnum::Value]);
			// $remark=array(
			// 	'is_add'=>false,
			// 	'folder_img'=>$folder_img
			// 	);
			// exit(retJson("修改成功.", true,$document,$remark));
			exit(retJson("修改成功.", true,$document));
		}
	}



	function tableEdit2($id,$folder_id=false){
		$connar['where']=$this->sqlEscape('db_table2.id=??',array($id));
		$connar['join']=array('db_admin','db_admin.id=db_table2.admin_id');
		$connar['items']="db_table2.*,db_admin.usercode,db_admin.username";
		$data['detail']=$this->Table2_model->get_single_full($connar);

		if($id==0){
			$data['title']=OtherTableType::Table2[XPHEnum::Caption]."（新增）";
			$data['SupervisionOtherImg'] = [];
		}
		else{
			$data['title']=OtherTableType::Table2[XPHEnum::Caption]."（".$data['detail']['name']."）";
			if(empty($data['detail']['img'])){
				$data['SupervisionOtherImg'] = [];
			}else{
				$data['SupervisionOtherImg'] = explode(',',$data['detail']['img']);
			}
		}

		$data['folder_id']=$folder_id;
		$data['AttendType']= $this->table_service->getAttendType(getSess()['id'],false);

		$this->load->view('admin/tableEdit2.php',$data);
	}
	function tableSave2(){
		$_POST['content']=$this->NOTXSS_POST['content'];
		$_POST['advice']=$this->NOTXSS_POST['advice'];
		unset($_POST['editorValue']);

		$table2 = copyArray($_POST,array('id','name',"address","type","sub_time",'content','advice','folder_id','AttendType'));
		$table2['sub_time']=strtotime($table2['sub_time']);

		//自增字段
		$table2['admin_id']=getSess()['id'];
		$table2['status']=CommonStatus::UnDeleted[XPHEnum::Value];

		if($table2['AttendType'] == '-1'){
			exit(retJson('请选择督导身份',false));
		}

		if(isset($_POST['SupervisionOtherImg'])){
			$file_img = $_POST['SupervisionOtherImg'];
		}else{
			$file_img = "";
		}

		$table2['img'] = "";
		if(is_array($file_img)){
			foreach($file_img as $k => $v){
				if($k == 0){
					$table2['img'] = $v;
				}else{
					$table2['img'] .= ','.$v;
				}
			}
		}else{
			$table2['img'] = $file_img;
		}

		if(!isset($_POST['id']) || $_POST['id'] == ""){
			$table2['created']=time();
			$id=$this -> Table2_model -> add($table2);
			$document=$this->table_service->getDocumentByIdAndType($id,OtherTableType::Table2[XPHEnum::Value]);

			// 其他材料统计
			$this->otherStatistics($table2['admin_id'], 'patrol');

			// $folder_img=$this->table_service->getFolderImg($id,OtherTableType::Table2[XPHEnum::Value]);
			// $folder_document=$this->table_service->getDocumentByFolderId($document['folder_id']);
			// if(count($folder_document)>0){
			// 	$this->Folder_model->update(array('id'=>$document['folder_id'],'is_have'=>CommonWhether::Whether[XPHEnum::Value]));
			// }
			// $remark=array(
			// 	'is_add'=>true,
			// 	'folder_img'=>$folder_img
			// 	);
			// exit(retJson("添加成功.", true,$document,$remark));
			exit(retJson("添加成功.", true,$document));
		}else{	
			unset($table2['name']);
			$table2['updated']=time();
			$this -> Table2_model -> update($table2);
			$document=$this->table_service->getDocumentByIdAndType($table2['id'],OtherTableType::Table2[XPHEnum::Value]);
			// $folder_img=$this->table_service->getFolderImg($table2['id'],OtherTableType::Table2[XPHEnum::Value]);
			// $remark=array(
			// 	'is_add'=>false,
			// 	'folder_img'=>$folder_img
			// 	);
			// exit(retJson("修改成功.", true,$document,$remark));
			exit(retJson("修改成功.", true,$document));
		}
	}


	function tableEdit3($id,$folder_id=false){
		$connar['where']=$this->sqlEscape('db_table3.id=??',array($id));
		$connar['join']=array('db_admin','db_admin.id=db_table3.admin_id');
		$connar['items']="db_table3.*,db_admin.usercode,db_admin.username";
		$data['detail']=$this->Table3_model->get_single_full($connar);

		if($id==0){
			$data['title']=OtherTableType::Table3[XPHEnum::Caption]."（新增）";
			$data['SupervisionOtherImg'] = [];
		}
		else{
			$data['title']=OtherTableType::Table3[XPHEnum::Caption]."（".$data['detail']['name']."）";
			if(empty($data['detail']['img'])){
				$data['SupervisionOtherImg'] = [];
			}else{
				$data['SupervisionOtherImg'] = explode(',',$data['detail']['img']);
			}
		}

		$data['folder_id']=$folder_id;

		$data['AttendType']= $this->table_service->getAttendType(getSess()['id'],false);
		$this->load->view('admin/tableEdit3.php',$data);
	}
	function tableSave3(){
		$_POST['content']=$this->NOTXSS_POST['content'];
		$_POST['advice']=$this->NOTXSS_POST['advice'];
		unset($_POST['editorValue']);
		$table3 = copyArray($_POST,array('id','name',"address","content","advice","sub_time",'folder_id','AttendType'));
		$table3['sub_time']=strtotime($table3['sub_time']);

		//自增字段
		$table3['admin_id']=getSess()['id'];
		$table3['status']=CommonStatus::UnDeleted[XPHEnum::Value];

		if($table3['AttendType'] == '-1'){
			exit(retJson('请选择督导身份',false));
		}


		if(isset($_POST['SupervisionOtherImg'])){
			$file_img = $_POST['SupervisionOtherImg'];
		}else{
			$file_img = "";
		}

		$table3['img'] = "";
		if(is_array($file_img)){
			foreach($file_img as $k => $v){
				if($k == 0){
					$table3['img'] = $v;
				}else{
					$table3['img'] .= ','.$v;
				}
			}
		}else{
			$table3['img'] = $file_img;
		}

		if(!isset($_POST['id']) || $_POST['id'] == ""){
			$table3['created']=time();
			$id=$this -> Table3_model -> add($table3);
			$document=$this->table_service->getDocumentByIdAndType($id,OtherTableType::Table3[XPHEnum::Value]);

			// 其他材料统计
			$this->otherStatistics($table3['admin_id'], 'tourInformant');

			// $folder_img=$this->table_service->getFolderImg($id,OtherTableType::Table3[XPHEnum::Value]);
			// $folder_document=$this->table_service->getDocumentByFolderId($document['folder_id']);
			// if(count($folder_document)>0){
			// 	$this->Folder_model->update(array('id'=>$document['folder_id'],'is_have'=>CommonWhether::Whether[XPHEnum::Value]));
			// }
			// $remark=array(
			// 	'is_add'=>true,
			// 	'folder_img'=>$folder_img
			// 	);
			// exit(retJson("添加成功.", true,$document,$remark));
			exit(retJson("添加成功.", true,$document));
		}else{	
			unset($table3['name']);
			$table3['updated']=time();
			$this -> Table3_model -> update($table3);
			$document=$this->table_service->getDocumentByIdAndType($table3['id'],OtherTableType::Table3[XPHEnum::Value]);
			// $folder_img=$this->table_service->getFolderImg($table3['id'],OtherTableType::Table3[XPHEnum::Value]);
			// $remark=array(
			// 	'is_add'=>false,
			// 	'folder_img'=>$folder_img
			// 	);
			// exit(retJson("修改成功.", true,$document,$remark));
			exit(retJson("修改成功.", true,$document));
		}
	}




	function tableEdit4($id,$folder_id=false){
		$connar['cond']=array('db_table4.id'=>$id);		
  //       $connar['join'][0]=array('admin a2','a.id=db_table4.admin_id');  
		// $connar['join'][1]=array('admin a1','a.id=db_table4.teacher_id');		
		// $connar['items']=" db_table4.*,a.dept_name,a.username,a.usercode ";
		$connar['join'][0]=array('admin a1','a1.id=db_table4.admin_id');  
        $connar['join'][1]=array('admin a2','a2.id=db_table4.teacher_id');         
        $connar['items']=" db_table4.*,a1.username admin_username,a1.usercode admin_usercode,a2.dept_name,a2.username teacher_username,a2.usercode teacher_usercode";
		$data['detail']=$this->Table4_model->get_single_full($connar);

		if($id==0){
			$data['title']=OtherTableType::Table4[XPHEnum::Caption]."（新增）";
			$data['SupervisionOtherImg'] = [];
		}
		else{
			$data['title']=OtherTableType::Table4[XPHEnum::Caption]."（".$data['detail']['name']."）";
			if(empty($data['detail']['img'])){
				$data['SupervisionOtherImg'] = [];
			}else{
				$data['SupervisionOtherImg'] = explode(',',$data['detail']['img']);
			}
		}

		$data['folder_id']=$folder_id;
		$data['teacher']=$this->admin_service->getAllAdmin();

		$data['AttendType']= $this->table_service->getAttendType(getSess()['id'],false);

		$this->load->view('admin/tableEdit4.php',$data);
	}
	function tableSave4(){
		$_POST['student_status']=$this->NOTXSS_POST['student_status'];
		$_POST['teacher_status']=$this->NOTXSS_POST['teacher_status'];
		$_POST['other_content']=$this->NOTXSS_POST['other_content'];
		$_POST['advice']=$this->NOTXSS_POST['advice'];
		unset($_POST['editorValue']);
		$table4 = copyArray($_POST,array('id','name',"title",'address','teacher_id','teacher_dept_name',"student_status","teacher_status","other_content","advice","sub_time",'folder_id','AttendType'));
		if($table4['teacher_id']==0){
			exit(retJson("请选择授课教师.", false));
		}
		$table4['sub_time']=strtotime($table4['sub_time']);


		if($table4['AttendType'] == '-1'){
			exit(retJson('请选择督导身份',false));
		}

		//自增字段
		$table4['admin_id']=getSess()['id'];
		$table4['status']=CommonStatus::UnDeleted[XPHEnum::Value];


		if(isset($_POST['SupervisionOtherImg'])){
			$file_img = $_POST['SupervisionOtherImg'];
		}else{
			$file_img = "";
		}

		$table4['img'] = "";
		if(is_array($file_img)){
			foreach($file_img as $k => $v){
				if($k == 0){
					$table4['img'] = $v;
				}else{
					$table4['img'] .= ','.$v;
				}
			}
		}else{
			$table4['img'] = $file_img;
		}
		if(!isset($_POST['id']) || $_POST['id'] == ""){
			$table4['created']=time();
			$id=$this -> Table4_model -> add($table4);
			$document=$this->table_service->getDocumentByIdAndType($id,OtherTableType::Table4[XPHEnum::Value]);

			// 其他材料统计
			$this->otherStatistics($table4['admin_id'], 'specialInspection');

			// $folder_img=$this->table_service->getFolderImg($id,OtherTableType::Table4[XPHEnum::Value]);
			// $folder_document=$this->table_service->getDocumentByFolderId($document['folder_id']);
			// if(count($folder_document)>0){
			// 	$this->Folder_model->update(array('id'=>$document['folder_id'],'is_have'=>CommonWhether::Whether[XPHEnum::Value]));
			// }
			// $remark=array(
			// 	'is_add'=>true,
			// 	'folder_img'=>$folder_img
			// 	);
			// exit(retJson("添加成功.", true,$document,$remark));
			exit(retJson("添加成功.", true,$document));
		}else{	
			unset($table4['name']);
			$table4['updated']=time();
			$this -> Table4_model -> update($table4);
			$document=$this->table_service->getDocumentByIdAndType($table4['id'],OtherTableType::Table4[XPHEnum::Value]);
			// $folder_img=$this->table_service->getFolderImg($table4['id'],OtherTableType::Table4[XPHEnum::Value]);
			// $remark=array(
			// 	'is_add'=>false,
			// 	'folder_img'=>$folder_img
			// 	);
			// exit(retJson("修改成功.", true,$document,$remark));
			exit(retJson("修改成功.", true,$document));
		}
	}

	function tableEdit5($id,$folder_id=false){
		$data['self']=$this->admin_service->getAdminById(getSess()['id']);
		$connar['where']=$this->sqlEscape('db_table5.id=??',array($id));
		$connar['join']=array('db_admin','db_admin.id=db_table5.admin_id');
		$connar['items']="db_table5.*,db_admin.usercode,db_admin.username";
		$data['detail']=$this->Table5_model->get_single_full($connar);

		$data['student']=$this->table_service->getTable5Student($id);

		if($id==0){
			$data['title']=OtherTableType::Table5[XPHEnum::Caption]."（新增）";
			$data['SupervisionOtherImg'] = [];
		}
		else{
			$data['title']=OtherTableType::Table5[XPHEnum::Caption]."（".$data['detail']['name']."）";
			if(empty($data['detail']['img'])){
				$data['SupervisionOtherImg'] = [];
			}else{
				$data['SupervisionOtherImg'] = explode(',',$data['detail']['img']);
			}
		}

		$data['folder_id']=$folder_id;
		$data['officer']=$this->admin_service->getAdminByRoleArray(array(WebRole::StudentInfoOfficer[XPHEnum::Value],WebRole::UnitStudentInfoOfficer[XPHEnum::Value]));

		$data['AttendType']= $this->table_service->getAttendType(getSess()['id'],false);
		$this->load->view('admin/tableEdit5.php',$data);
	}
	function tableSave5(){
		$_POST['task']=$this->NOTXSS_POST['task'];
		$_POST['advice']=$this->NOTXSS_POST['advice'];
		$_POST['summary']=$this->NOTXSS_POST['summary'];
		
		$table5 = copyArray($_POST,array('id','name',"teacher_dept_name",'sub_time','unit_name','unit_address',"unit_contact","unit_phone","task","leader_name","task_time",'student_num','eval1','eval1_remark','eval2','eval2_remark','eval3','eval3_remark','eval4','eval4_remark','eval5','eval5_remark','eval6','eval6_remark','eval7','eval7_remark','advice','mentor_name','mentor_phone','mentor_time','summary','folder_id','AttendType'));

		if($table5['AttendType'] == '-1'){
			exit(retJson('请选择督导身份',false));
		}
		$table5['sub_time']=strtotime($table5['sub_time']);
		$table5['task_time']=strtotime($table5['task_time']);
		$table5['mentor_time']=strtotime($table5['mentor_time']);

		//自增字段
		$table5['admin_id']=getSess()['id'];
		$table5['status']=CommonStatus::UnDeleted[XPHEnum::Value];


		if(isset($_POST['SupervisionOtherImg'])){
			$file_img = $_POST['SupervisionOtherImg'];
		}else{
			$file_img = "";
		}

		$table5['img'] = "";
		if(is_array($file_img)){
			foreach($file_img as $k => $v){
				if($k == 0){
					$table5['img'] = $v;
				}else{
					$table5['img'] .= ','.$v;
				}
			}
		}else{
			$table5['img'] = $file_img;
		}
		if(!isset($_POST['id']) || $_POST['id'] == ""){
			$table5['created']=time();
			$id=$this -> Table5_model -> add($table5);
			$document=$this->table_service->getDocumentByIdAndType($id,OtherTableType::Table5[XPHEnum::Value]);

			// 其他材料统计
			$this->otherStatistics($table5['admin_id'], 'postPractice');

			// $folder_img=$this->table_service->getFolderImg($id,OtherTableType::Table5[XPHEnum::Value]);
			// $folder_document=$this->table_service->getDocumentByFolderId($document['folder_id']);
			// if(count($folder_document)>0){
			// 	$this->Folder_model->update(array('id'=>$document['folder_id'],'is_have'=>CommonWhether::Whether[XPHEnum::Value]));
			// }
			// $remark=array(
			// 	'is_add'=>true,
			// 	'folder_img'=>$folder_img
			// 	);

			//与其他表不同，增加子表学生信息
			if(isset($_POST['student_class_name'])){
				$default_sql=$sql=" insert into db_table5_student (table5_id,student_class_name,student_name,contact_phone) values ";
				foreach ($_POST['student_class_name'] as $k => $v) {
					if($sql!=$default_sql){
						$sql.=" , ";
					}
					$sql.=$this->sqlEscape(" (??,??,??,??) ",array($id,$v,$_POST['student_name'][$k],$_POST['contact_phone'][$k]));
				}
				if($sql!=$default_sql){
					$this->Table5_student_model->query($sql,false);
				}
			}

			// exit(retJson("添加成功.", true,$document,$remark));
			exit(retJson("修改成功.", true,$document));
		}else{	
			unset($table5['name']);
			$table5['updated']=time();
			$this -> Table5_model -> update($table5);
			$document=$this->table_service->getDocumentByIdAndType($table5['id'],OtherTableType::Table5[XPHEnum::Value]);
			// $folder_img=$this->table_service->getFolderImg($table5['id'],OtherTableType::Table5[XPHEnum::Value]);
			// $remark=array(
			// 	'is_add'=>false,
			// 	'folder_img'=>$folder_img
			// 	);

			//与其他表不同，增加子表学生信息
			$this->Table5_student_model->delBatch($this->sqlEscape(" table5_id=?? ",array($table5['id'])));
			if(isset($_POST['student_class_name'])){
				$default_sql=$sql=" insert into db_table5_student (table5_id,student_class_name,student_name,contact_phone) values ";
				foreach ($_POST['student_class_name'] as $k => $v) {
					if($sql!=$default_sql){
						$sql.=" , ";
					}
					$sql.=$this->sqlEscape(" (??,??,??,??) ",array($table5['id'],$v,$_POST['student_name'][$k],$_POST['contact_phone'][$k]));
				}
				if($sql!=$default_sql){
					$this->Table5_student_model->query($sql,false);
				}
			}

			// exit(retJson("修改成功.", true,$document,$remark));
			exit(retJson("修改成功.", true,$document));
		}
	}



	function tableEdit6($id,$folder_id){
		$connar['cond']=array('db_table6.id'=>$id);
		$connar['join']=array('admin a','a.id=db_table6.officer_id');
		$connar['items']=" db_table6.*,a.dept_name,a.class_name ";
		$data['detail']=$this->Table6_model->get_single_full($connar);

		if($id==0){
			$data['title']=OtherTableType::Table6[XPHEnum::Caption]."（新增）";
		}
		else{
			$data['title']=OtherTableType::Table6[XPHEnum::Caption]."（".$data['detail']['name']."）";
		}

		$data['folder_id']=$folder_id;
		$data['officer']=$this->admin_service->getAdminByRoleArray(array(WebRole::StudentInfoOfficer[XPHEnum::Value],WebRole::UnitStudentInfoOfficer[XPHEnum::Value]));

		$this->load->view('admin/tableEdit6.php',$data);
	}
	function tableSave6(){
		$table6 = copyArray($_POST,array('id','name','officer_id','officer_dept_name','officer_class_name',"content","advice","sub_time","deal_time",'folder_id'));
		if($table6['officer_id']==0){
			exit(retJson("请选择信息员.", false));
		}
		$table6['sub_time']=strtotime($table6['sub_time']);
		$table6['deal_time']=strtotime($table6['deal_time']);

		//自增字段
		$table6['admin_id']=getSess()['id'];
		$table6['status']=CommonStatus::UnDeleted[XPHEnum::Value];
		if(!isset($_POST['id']) || $_POST['id'] == ""){
			$table6['created']=time();
			$id=$this -> Table6_model -> add($table6);
			$document=$this->table_service->getDocumentByIdAndType($id,OtherTableType::Table6[XPHEnum::Value]);
			$folder_img=$this->table_service->getFolderImg($id,OtherTableType::Table6[XPHEnum::Value]);
			$folder_document=$this->table_service->getDocumentByFolderId($document['folder_id']);
			if(count($folder_document)>0){
				$this->Folder_model->update(array('id'=>$document['folder_id'],'is_have'=>CommonWhether::Whether[XPHEnum::Value]));
			}
			$remark=array(
				'is_add'=>true,
				'folder_img'=>$folder_img
				);


			// 其他材料统计
			$this->otherStatistics($table6['admin_id'], 'messenger');

			exit(retJson("添加成功.", true,$document,$remark));
		}else{	
			unset($table6['name']);
			$table6['updated']=time();
			$this -> Table6_model -> update($table6);
			$document=$this->table_service->getDocumentByIdAndType($table6['id'],OtherTableType::Table6[XPHEnum::Value]);
			$folder_img=$this->table_service->getFolderImg($table6['id'],OtherTableType::Table6[XPHEnum::Value]);
			$remark=array(
				'is_add'=>false,
				'folder_img'=>$folder_img
				);
			exit(retJson("修改成功.", true,$document,$remark));
		}
	}


	function test($id,$folder_id=false){
		$connar['where']=$this->sqlEscape('db_table1.id=??',array($id));
		$connar['join']=array('db_admin','db_admin.id=db_table1.admin_id');
		$connar['items']="db_table1.*,db_admin.usercode,db_admin.username";
		$data['detail']=$this->Table1_model->get_single_full($connar);

		if($id==0){
			$data['title']=OtherTableType::Table1[XPHEnum::Caption]."（新增）";
		}
		else{
			$data['title']=OtherTableType::Table1[XPHEnum::Caption]."（".$data['detail']['name']."）";
		}

		$data['folder_id']=$folder_id;

		$data['AttendType']= $this->table_service->getAttendType(getSess()['id'],false);

		$this->load->view('admin/test.php',$data);
	}


	function test_1(){

		$origin = isset($_SERVER['HTTP_ORIGIN'])? $_SERVER['HTTP_ORIGIN'] : '';

		$allow_origin = array(
		    'http://sub1.example.com',
		    'http://sub2.example.com'
		);

		if(in_array($origin, $allow_origin)){
		    header('Access-Control-Allow-Origin:'.$origin); //跨域访问
			header("Access-Control-Allow-Credentials", "true");
		}

		header('Content-type: application/json');

		echo(json_encode($this->upload_handle()));
	}

	// 这只是一个示例
	// This is a demo

	function  upload_handle (){
		$result=array ("success"=>false,"message"=>"Null");
		$file_size_limit=300*1024; // 300KB
		if (in_array($_FILES["imageFile"]["type"],array ("image/gif","image/jpeg","image/pjpeg","image/png"))){
			if ($_FILES["imageFile"]["error"]>0){
				$result['message']="error";
			}
			elseif ($_FILES["imageFile"]["size"]>$file_size_limit){
				$result['message']="File too large";
			}else {
				$file_name="upload/".md5_file($_FILES["imageFile"]["tmp_name"]).str_replace("image/",".",$_FILES["imageFile"]["type"]);
				if (!file_exists($file_name)){
					move_uploaded_file($_FILES["imageFile"]["tmp_name"],$file_name);
				}
				$result['success']=true;
				$result['message']=$file_name;
			}
		}else {
			$result['message']="Invalid file";
		}
		return $result;
	}



	// 其他材料统计 field:字段名
	private function otherStatistics ($admin_id, $field)
	{
		$other = $this->Other_statistics_model->get_single(array('admin_id' => $admin_id));
		if (empty($other)) {
			$admin = $this->Admin_model->get_single(array('id' => $admin_id));
			$add = array(
				'admin_id'  => $admin_id,
				'username'  => $admin['username'],
				'dept_name' => $admin['dept_name'],
				$field      => 1,
			);
			$this->Other_statistics_model->add($add);
		} else {
			$update['id'] = $other['id'];
			$update[$field] = $other[$field]+1;
			$this->Other_statistics_model->update($update);
		}
	}
}